//牛客 KY258 日期累加
#include <iostream>
using namespace std;

ostream& operator<<(ostream& out, const Date& d);
class Date
{
    //友元
    friend ostream& operator<<(ostream& out, const Date& d);

public:
    // 获取某年某月的天数
	int GetMonthDay(int year, int month) const;
    //打印接口
	void Print() const;
	// 全缺省的构造函数
	Date(int year = 1, int month = 1, int day = 1);
	// 拷贝构造函数
	// d2(d1)
	Date(const Date& d);
    // 日期-=天数
	Date& operator-=(int day);
	// 日期+=天数
	Date& operator+=(int day);
	// 日期+天数
	Date operator+(int day) const;

private:
    int _year;
    int _month;
    int _day;
};


// 获取某年某月的天数
int Date::GetMonthDay(int year, int month) const
{
    const static int monthArray[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };

    if(2 == month
        && ((year%4 == 0 && year%100 != 0) || (year%400 == 0)))
        {
            return 29; 
        }
        
    
    return monthArray[month];
}
// 全缺省的构造函数
Date::Date(int year, int month, int day)
{
    _year = year;
    _month = month;
    _day = day;
}
// 拷贝构造函数
// d2(d1)
Date::Date(const Date& d)
{
    _year = d._year;
    _month = d._month;
    _day = d._day;
}
// 日期-=天数
Date& Date::operator-=(int day)
{
    if(day < 0)
    {
        return *this += (-day);
    }

    _day -= day;

    while(_day <= 0)
    {
        _month--;
        if(0 == _month)
        {
            _year--;
            _month = 12;
        }
        _day += GetMonthDay(_year, _month);
    }

    return *this;
}
// 日期+=天数
Date& Date::operator+=(int day)
{
    if(day < 0)
    {
        return *this -= (-day);
    }

    _day += day;
    while(_day > GetMonthDay(_year, _month))
    {
        //月进位
        _day -= GetMonthDay(_year, _month);
        _month++;

        //月满了
        if(13 == _month)
        {
            _year++;
            _month = 1;
        }
    }

    return *this;
}
// 日期+天数
Date Date::operator+(int day) const
{
    Date tmp(*this);
    tmp += day;
    return tmp;
}
ostream& operator<<(ostream& out, const Date& d)
{
    if(d._month < 10 && d._day < 10)
        out << d._year << "-" << 0 << d._month << "-" << 0 << d._day;
    else if(d._month < 10 && d._day >= 10)
        out << d._year << "-" << 0 << d._month << "-" << d._day;
    else if(d._month >= 10 && d._day < 10)
        out << d._year << "-" << d._month << "-" << 0 << d._day;
    else
        out << d._year << "-" << d._month << "-" << d._day;

    return out;
}
int main() {
    int n = 0;
    cin >> n;
    int year = 0, month = 0, day = 0, add = 0;
    while(n--)
    {
        cin >> year >> month >> day >> add;
        Date d(year, month, day);
        Date d1 = d + add;
        cout << d1 << endl;
    }
}